﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Imaging;

namespace LunarSF.SHomeWorkshop.LunarMarkdownEditor
{
    public class WorkSpaceItemPopupBar : Popup
    {
        public WorkSpaceItemPopupBar(WorkspaceTreeViewItem ownerItem)
        {
            this.ownerItem = ownerItem;
            this.Placement = PlacementMode.Mouse;

            StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal, };
            btnOpen.Style = FindResource("SquareButtonStyle") as Style;
            btnOpen.BorderThickness = new Thickness(1);
            btnOpen.ToolTip = ((ownerItem == null || string.IsNullOrWhiteSpace(ownerItem.Title)) ? "打开文件" : $"打开 {ownerItem.Title}");
            btnOpen.Click += BtnOpen_Click;
            sp.Children.Add(btnOpen);
            this.Child = sp;
        }

        private WorkspaceTreeViewItem ownerItem = null;

        public WorkspaceTreeViewItem OwnerItem
        {
            get { return this.ownerItem; }
        }

        private void BtnOpen_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this.ownerItem != null) this.ownerItem.OpenFile();
        }

        private Button btnOpen = new Button()
        {
            Padding = new Thickness(1),
            Height = 24,
            Width = 24,
            Content = new Image()
            {
                Width = 16,
                Height = 16,
                Source = new BitmapImage(new Uri("pack://application:,,,/LunarMarkdownEditor;component/Images/openHS.png")),
            },
        };
    }
}
